import { createApp } from 'vue'
import App from './App.vue'
import store, { useAuthStore, initStoreData } from './store/index'
import router from './router/index'
import SgDirectives from './directives/index'
import { init as cryptoInit } from './utils/crypto'
import Xss from 'xss'
import SgComponents from './ui/index'
import filters from './filters/index'

import './style/index.scss'

const app = createApp(App)
const { globalProperties } = app.config
globalProperties.$xss = Xss

globalProperties.$toastLogin = function (msg = '请#{ 登陆 }后再操作', params: any) {
  const authStore = useAuthStore()
  if (authStore.isLogin) {
    return
  }
  window._sgGlobal.$toast(msg, {
    ...params,
    btnCall: () => {
      router.push({ name: 'login', query: { redirect: router.currentRoute.value.fullPath } })
    }
  })
}
window._sgGlobal.$toastLogin = globalProperties.$toastLogin

app.use(store)
app.use(router)
app.use(SgComponents)
app.use(SgDirectives)
app.use(filters)

cryptoInit()
initStoreData()

app.mount('#app')

window._sgApp = app
